IF OBJECT_ID('dbo.vwAgreementProjectBudgets') IS NOT NULL
BEGIN
    DROP VIEW dbo.vwAgreementProjectBudgets
    IF OBJECT_ID('dbo.vwAgreementProjectBudgets') IS NOT NULL
        PRINT '<<< FAILED DROPPING VIEW dbo.vwAgreementProjectBudgets >>>'
    ELSE
        PRINT '<<< DROPPED VIEW dbo.vwAgreementProjectBudgets >>>'
END
GO
-- =======================================================================
-- Object Name: (VIEW) dbo.vwAgreementProjectBudgets
--
-- Author:      Kevin Cashman, Parallax Consulting LLC
--
-- Create date: 8/23/2007
--
-- Description: View to get Project-level Budget data, 
--
-- Used BY Procedure/Report: dbo.RptInvestigatorActivity() (and others)
--
--------------------------------------------------------------------------
-- Date        Initials  Modification
--------------------------------------------------------------------------
-- 8/23/07     KC        Created
-- 9/7/07      KC        Changed for new version of AgrAgreement_Budget
-- 9/8/07      KC        Added IndirectCostRate
--
-- =======================================================================
CREATE VIEW dbo.vwAgreementProjectBudgets
AS
SELECT    AgreementId,
          MIN(BudgetStartDate) AS ProjectStartDate,
          MAX(BudgetEndDate) AS ProjectEndDate,
          SUM(AB.BudgetDirectCost) AS ProjectDirectCost,
          SUM(AB.BudgetIndirectCost) AS ProjectIndirectCost,
          MAX(AB.IndirectCostRate) AS IndirectCostRate
FROM      dbo.AgrAgreement_Budget AB
GROUP BY AgreementId 
GO

IF OBJECT_ID('dbo.vwAgreementProjectBudgets') IS NOT NULL
    PRINT '<<< CREATED VIEW dbo.vwAgreementProjectBudgets >>>'
ELSE
    PRINT '<<< FAILED CREATING VIEW dbo.vwAgreementProjectBudgets >>>'
GO
